{extend name="common/__base" /}
{block name="body"}

<form class="layui-form" action="" onsubmit="return false;" method="post">
    <input type="hidden" name="id" value="{$data.id}">
    <!-- 网站名称 -->
    <div class="layui-form-item">
        <label class="layui-form-label">网站名称：</label>
        <div class="layui-input-inline">
            <input type="text" name="website_name" value="{$data.website_name}" placeholder="请输入网站名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- app名称 -->
    <div class="layui-form-item">
        <label class="layui-form-label">app名称：</label>
        <div class="layui-input-inline">
            <input type="text" name="app_name" value="{$data.app_name}" placeholder="请输入app名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- 图片 -->
    <div class="layui-form-item">
        <label class="layui-form-label">图片：</label>
        <input type="hidden" name="logo" value="{$data.logo}" required="" lay-filter="required">
        <div class="layui-input-inline uploadHeadImage">
            <div class="layui-upload-drag" id="logo">
                <i class="layui-icon"></i>
                <p>点击上传图片，或将图片拖拽到此处</p>
            </div>
        </div>
        <div class="layui-input-inline">
            <div class="layui-upload-list">
                <img class="layui-upload-img headImage" width="128px" height="128px" src="{$data.logo ?: 'http://t.cn/RCzsdCq'}" id="demo3">
                <p id="demoText3"></p>
            </div>
        </div>
        <span class="domino label-warning font-red">（上传200px*200px的像素图）</span>
    </div>
    <!-- 安卓版本 -->
    <div class="layui-form-item">
        <label class="layui-form-label">安卓版本：</label>
        <div class="layui-input-inline">
            <input type="text" name="android_version" value="{$data.android_version}" placeholder="请输入安卓版本" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- 安卓下载链接 -->
    <div class="layui-form-item">
        <label class="layui-form-label">安卓下载链接：</label>
        <div class="layui-input-inline">
            <input type="text" name="android_url" value="{$data.android_url}" placeholder="请输入安卓下载链接" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- ios版本 -->
    <div class="layui-form-item">
        <label class="layui-form-label">ios版本：</label>
        <div class="layui-input-inline">
            <input type="text" name="ios_version" value="{$data.ios_version}" placeholder="请输入ios版本" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- ios下载链接 -->
    <div class="layui-form-item">
        <label class="layui-form-label">ios下载链接：</label>
        <div class="layui-input-inline">
            <input type="text" name="ios_url" value="{$data.ios_url}" placeholder="请输入ios下载链接" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- ios上架版本 -->
    <div class="layui-form-item">
        <label class="layui-form-label">ios上架版本：</label>
        <div class="layui-input-inline">
            <input type="text" name="ios_up_version" value="{$data.ios_up_version}" placeholder="请输入ios上架版本" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="formSubmit">立即提交</button>
        </div>
    </div>
</form>
{/block}
{block name="js"}
<script type="text/javascript">
        var form = layui.form;
        var layer = layui.layer;
        var upload = layui.upload;
        form.render();

        var uploadInst3 = upload.render({
            elem: '#logo',
            url: '{:url("admin/upload/image")}',
            data: {event: 'image'},
            size: 1024,
            before: function (obj) {
                // 预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo3').attr('src', result); //图片链接（base64）
                });
            },
            done: function (res) {
                //如果上传失败
                if (res.code == 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                //打印后台传回的地址: 把地址放入一个隐藏的input中, 和表单一起提交到后台, 此处略..
                $("input[name='logo']").val(res.data.image);
                var demoText = $('#demoText3');
                demoText.html('<span style="color: #8f8f8f;">上传成功!!!</span>');
            },
            error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText3');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst3.upload();
                });
            }
        });

        form.on('submit(formSubmit)', function (data) {
            ajaxRequest('{:url("index")}', data.field)
                .then(function(ret){
                    if (ret.code == 1) {
                        showMsg(ret.msg,{icon:1});
                        setTimeout(function(){
                            closeWindow();
                        },1000);
                    } else {
                        showMsg(ret.msg,{icon:2});
                        return false;
                    }
                })
                .catch(function(err){
                    console.log(JSON.stringify(err));
                });
        });
</script>
{/block}
